package com.archgeek.bigdata;

import java.io.*;
import java.util.Map;
import java.util.Properties;

/**
 * @author pizhihui
 * @date 2022-03-12
 */
public class FileUtils {


    private static final String FILE = "config.properties";

    public static Properties get() throws IOException {
        File file = new File(FILE);
        if (!file.exists()) {
            return getResourceConfig();
            // throw new FileNotFoundException("Properties file" + file.getAbsolutePath() + " does not exist");
        }
        Properties properties = new Properties();
        try (FileInputStream fis = new FileInputStream(file)) {
            properties.load(fis);
        }
        return properties;

    }

    public static Properties getResourceConfig() throws IOException {
        InputStream resourceAsStream = FileUtils.class.getClassLoader().getResourceAsStream(FILE);
        Properties properties = new Properties();
            properties.load(resourceAsStream);
        return properties;
    }

    public static void main(String[] args) throws IOException {
        System.out.println(getResourceConfig().toString());
    }


}
